#coding:utf-8


import json

from cos import scut,norm

def getCount(location):
    vMax = 0.0
    vMin = 0.0
    vM = 0.0
    cnt = 0.0
    ss = 0.0

    x100 = 0
    with open(location) as f:
        for line in f:
            n = json.loads(line)
            v1 = n['v1']
            v2 = n['v2']
            v1 = scut(v1)
            v2 = scut(v2)
            vs = v1
            vs.extend(v2)
            for v,c in vs:
                if len(v) < 2: continue
                cnt += 1
                ss += c
                if c > vMax:
                    vMax = c
                if c < vMin:
                    vMin = c
                if c > 100.0:
                    x100 += 1
    vM = ss/cnt
    print vMax,vMin,vM
    print cnt,x100

def getVCount(location):
    vMax = 0.0
    vMin = 0.0
    vM = 0.0
    cnt = 0.0
    ss = 0.0

    x100 = 0
    with open(location) as f:
        for line in f:
            n = json.loads(line)
            v1 = n['v1']
            v2 = n['v2']
            v1 = scut(v1)
            v2 = scut(v2)
            if len(v1) < 5:
                continue
            if len(v2) < 5:
                continue
            v1 = {v:max(5,min(60,c)) for v,c in v1}
            v2 = {v:max(5,min(60,c)) for v,c in v2}
            v1 = norm(v1)
            v2 = norm(v2)
            v1 = v1.items()
            v2 = v2.items()
            vs = v1
            vs.extend(v2)
            for v,c in vs:
                if len(v) < 2: continue
                cnt += 1
                ss += c
                if c > vMax:
                    vMax = c
                    print n['i1'],n['i2'],json.dumps(vs,ensure_ascii=False)
                if c < vMin:
                    vMin = c
                if c > 0.6:
                    x100 += 1
    vM = ss/cnt
    print vMax,vMin,vM
    print cnt,x100


if __name__ == '__main__':

    location = 'data/issue.vv.txt'
    getVCount(location)

